<?php
/*
 * Created on 2011-5-13
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
 
function  json_str_to_array($json_str)
{
	if(!$json_str)
	{
		echo "$json_str is null";
	}
    else if(is_array($json_str))
    {
    	echo "is already arr";
        return $json_str;
    }
    else
    {
    	$object=($json_str)?json_decode($json_str):NULL;
    	if(!$object)
    	{
    		echo "obj is null:$json_str<br/>";
    	}
    	else if(is_object($object))
    	{
    		return  json_to_array($object);
    	}
    	else
    	{
    		echo "decode err<br/>";
    	}
    }
	return NULL;
}

function json_to_array($object)
{
	$arr=array();
	foreach($object as $key=>$a_value)
	{
		if(is_object($a_value))
		{
			$arr[$key]=json_to_array($a_value);
		}
		else
		{
			$arr[$key]=$a_value;
		}
	}
	return $arr;
}
 
 function gbk2utf8($data)
 {
 	if(is_array($data))
 	{
 		return array_map('gbk2utf8',$data);
 	}
 	return iconv('gbk','utf-8',$data);
 }
 
 
?>
